package com.wsl.myexception.controller;

import com.wsl.myexception.domain.Result;
import com.wsl.myexception.exception.WslException;
import com.wsl.myexception.utils.ResultUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Map;

/**
 * @author ：wangshuliang
 * @date ：Created in 2019/6/3 16:17
 * @description：统一异常处理
 * @modified By：
 */
@RestControllerAdvice
public class MyControllerAdvice {
    @ExceptionHandler(value = Exception.class)
    public Result handle(Exception e){
        if (e instanceof WslException){
            return ResultUtils.error(((WslException) e).getCode(),e.getMessage());
        }else{
            return ResultUtils.error(-1,"未知错误");
        }

    }
}
